package org.birrap.ejb;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.birrap.entities.VasosT;


@Stateless
public class VasosTBean implements VasosTBeanLocal {

    @PersistenceContext(unitName = "BirrApp-ejbPU")
    private EntityManager em;
    
    @Override
    public List<VasosT> findAll() {
    
    Query query = em.createNamedQuery("VasosT.findAll");
       
     return (List<VasosT>)query.getResultList();}

    @Override
    public VasosT findByIdVaso(Integer id) {

    VasosT res = null;
      Query query = em.createNamedQuery("VasosT.findByIdVaso").setParameter("id", id);
      
      try{
          res = (VasosT)query.getSingleResult();
      }
      catch (NoResultException e){
          System.out.println("No existe el id");
      }
      return res;
    }

    @Override
    public List<VasosT> findByCapacidad(String capacidad) {
    
      List<VasosT> res = null;
      Query query = em.createNamedQuery("VasosT.findByCapacidad")
              .setParameter("capacidad","%" + capacidad+ "%");
      
      try{
          res = (List<VasosT>)query.getResultList();
      }
      catch (NoResultException e){
          System.out.println("No existe la capacidad");
      }
      return res;
    }

    @Override
    public List<VasosT> findByTipo(String tipo) {
     List<VasosT> res = null;
     Query query = em.createNamedQuery("VasosT.findByTipo")
              .setParameter("tipo","%" + tipo+ "%");
      
      try{
          res = (List<VasosT>)query.getResultList();
      }
      catch (NoResultException e){
          System.out.println("No existe el tipo");
      }
      return res;
    
    }

    @Override
    public VasosT insert(VasosT vaso) {
        return update(vaso);
    
    }

    @Override
    public VasosT update(VasosT vaso) {
        return em.merge(vaso);
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

}
